#!/usr/bin/python3
# _*_ coding: utf-8 _*_
#
# Copyright (C) 2024 - 2024 heihieyouheihei, Inc. All Rights Reserved 
#
# @Time    : 2024/9/11 14:25
# @Author  : Yuyun
# @File    : TreeNode.py
# @IDE     : PyCharm

class TreeNode:
    def __init__(self, val, left = None, right = None):
        self.val = val
        self.left = left
        self.right = right
class Solution:
    #   依据完全二叉树（或几乎完全）的先序遍历列表，无NULL值
    def buildtree_preorder(self, orderlist):
        def build(index):
            if index >= len(orderlist) or orderlist[index] is None:
                return None
            node = TreeNode(orderlist[index])
            node.left = build(2 * index + 1)
            node.right = build(2 * index + 2)
            return node
        return build(0)
